//
//  AsyncUtil.swift
//  show
//
//  Created by 李威 on 2022/3/13.
//

import Foundation

public typealias Task = () -> Void

struct AsyncUtil {
    
    public static func async(_ task: @escaping Task) {
        _async(task);
    }

    public static func async(_ task: @escaping Task, _ mainTask: @escaping Task){
        _async(task, mainTask);
    }
    private static func _async(_ task: @escaping Task, _ mainTask: Task? = nil) {
        let item = DispatchWorkItem(block: task);
        DispatchQueue.global().async(execute: item);
        if let main = mainTask {
            item.notify(queue: DispatchQueue.main, execute: main);
        }
    }
}
